package org.example.footshoppingmaster.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.example.footshoppingmaster.custom.ResultVO;
import org.example.footshoppingmaster.mapper.CartMapper;
import org.example.footshoppingmaster.pojo.DO.Cart;
import org.example.footshoppingmaster.pojo.DTO.CartProduct;
import org.example.footshoppingmaster.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
@Slf4j
public class CartServiceImpl implements CartService {

    @Autowired
    private  CartMapper cartMapper;
    /*
     * 向购物车添加数据
     * */
    @Override
    public ResultVO<?> insertGoods(Cart cart) {
        cart.setCreateTime(LocalDateTime.now());
        cart.setUpdateTime(LocalDateTime.now());
        int res= cartMapper.insertGoodsToCart(cart);
        if (res!=0){
            return  ResultVO.success("商品添加成功");
        }else {
            return ResultVO.error("商品添加失败");
        }
    }
    /*
    * 获取购物车商品列表
    * */
    @Override
    public List<CartProduct> selectCartList(Integer id) {
        return cartMapper.selectGoodsList(id);
    }
    /*
     * 删除购物车商品
     * */
    @Override
    public ResultVO<?> deleteCartGoods(Integer id) {
        if (cartMapper.deleteGoods(id)){
            return ResultVO.success("删除成功");
        }
        return ResultVO.error("删除失败");
    }
}
